package com.jiangyg.mall.member.service;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.utils.bean.BeanUtils;
import com.jiangyg.mall.db.mybatis.BaseServiceImpl;
import com.jiangyg.mall.member.dao.MemberLevelDao;
import com.jiangyg.mall.member.dto.MemberLevelDTO;
import com.jiangyg.mall.member.entity.MemberLevel;
import com.jiangyg.mall.member.vo.MemberLevelVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class MemberLevelServiceImpl extends BaseServiceImpl<MemberLevelDao, MemberLevel> implements MemberLevelService {

    @Autowired
    public MemberLevelServiceImpl(MemberLevelDao memberLevelDao) {
        super(memberLevelDao);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public Pagination<MemberLevelVO> selectPagination(Pagination<MemberLevelVO> pagination) throws Exception {
        return this.executeSelectPagination(pagination, MemberLevelVO.class);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public List<MemberLevelDTO> selectList() throws Exception {
        final List<MemberLevel> levelList = this.baseMapper.selectList(null);
        return BeanUtils.transformList(levelList, MemberLevelDTO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdate(MemberLevelDTO dto) throws Exception {
        return this.executeSaveOrUpdate(dto) > 0;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public MemberLevelVO selectById(Long memberLevelId) throws Exception {
        return this.executeSelectById(memberLevelId, MemberLevelVO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(List<Long> memberLevelIds) {
        return this.baseMapper.deleteBatchIds(memberLevelIds) > 0;
    }

}
